# zlib.cmake
# 本文件包含着从外部导入 zlib 所需要的信息

SET(ZLIB_SOURCES_DIR "${LIB_SOURCE_DIR}/extern_rocksdb" CACHE PATH "Path to ZLIB sources")
SET(ZLIB_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "ZLIB include directory." FORCE)
SET(ZLIB_LIBRARIES "${LIB_INSTALL_DIR}/libzlib.a" CACHE FILEPATH "ZLIB include directory." FORCE)

ExternalProject_Add(
        extern_zlib
        GIT_REPOSITORY https://github.com/madler/zlib.git
        URL https://github.com/madler/zlib/releases/download/v1.3.1/zlib-1.3.1.tar.gz
        CMAKE_ARGS
        -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX}
        -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
        -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
        BUILD_COMMAND make
)

ADD_LIBRARY(zlib STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET zlib PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES})
ADD_DEPENDENCIES(zlib extern_zlib)